package com.drug.mingkang.permission.service.impl;

import com.drug.mingkang.permission.model.PerUserRole;
import com.drug.mingkang.permission.mapper.PerUserRoleMapper;
import com.drug.mingkang.permission.service.PerUserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户角色表(PerUserRole)表服务实现类
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:14
 */
@Service("perUserRoleService")
public class PerUserRoleServiceImpl implements PerUserRoleService {
    @Resource
    private PerUserRoleMapper perUserRoleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param userRoleId 主键
     * @return 实例对象
     */
    @Override
    public PerUserRole queryById(Integer userRoleId) {
        return this.perUserRoleMapper.queryById(userRoleId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<PerUserRole> queryAllByLimit(int offset, int limit) {
        return this.perUserRoleMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param perUserRole 实例对象
     * @return 实例对象
     */
    @Override
    public PerUserRole insert(PerUserRole perUserRole) {
        this.perUserRoleMapper.insert(perUserRole);
        return perUserRole;
    }

    /**
     * 修改数据
     *
     * @param perUserRole 实例对象
     * @return 实例对象
     */
    @Override
    public PerUserRole update(PerUserRole perUserRole) {
        this.perUserRoleMapper.update(perUserRole);
        return this.queryById(perUserRole.getUserRoleId());
    }

    /**
     * 通过主键删除数据
     *
     * @param userRoleId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer userRoleId) {
        return this.perUserRoleMapper.deleteById(userRoleId) > 0;
    }
}